<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://shale.apache.org/core" prefix="s" %>

<html>
	<head>
		<title>"Group Validation" Sample Page</title>

		<script type="text/javascript">
			function setActiveValidationGroup(validationGroup) {
				document.getElementById('fld_activeValidationGroup').value=validationGroup;
			}
		</script>

	</head>
	<f:view>
	<body>
		<h:messages layout="list" id="messages1" styleClass="messages" showDetail="true" tooltip="true"></h:messages>
		<f:loadBundle var="lbl" basename="bundle/labels" />
		<f:loadBundle var="msg" basename="bundle/messages" />
		
		<h:form id="form1" onsubmit="return validateForm(this)">
			<table>
				<tbody>
				<tr>
					<td colspan="2">
						<table>
							<tbody>
							<tr>
								<td width="1%" nowrap="nowrap"><h:outputLabel value="#{lbl.companyName} (NV)" /></td>
								<td width="1%">:</td>
								<td align="left">
									<h:inputText id="txt_compname" value="#{validatorPageBean.companyName}" />
								</td>
							</tr>
							</tbody>
						</table>
					</td>
				</tr>
				<tr>
					<td colspan="2">
					<table>
						<tbody>
						<tr valign="top">
							<td>
								<fieldset id="nogroupfields" title="No-Group Fields">
									<table>
										<tbody>
										<tr>
											<td><h:outputLabel value="#{lbl.name} (NG)" /></td>
											<td>:</td>
											<td>
												<h:inputText id="txt_name" value="#{validatorPageBean.name}">
													<s:commonsValidator type="maxlength" arg="#{lbl.name}"  client="false" server="true" maxlength="20">
													</s:commonsValidator>
													<s:commonsValidator type="minlength" arg="#{lbl.name}"  client="false" server="true" minlength="3">
													</s:commonsValidator>
												</h:inputText>
											</td>
										</tr>
										<tr>
											<td><h:outputLabel value="#{lbl.age} (NG)" /></td>
											<td>:</td>
											<td>
												<h:inputText id="txt_age" value="#{validatorPageBean.age}">
													<s:commonsValidator type="intRange" arg="#{lbl.age}"  client="false" server="true" min="20" max="60">
													</s:commonsValidator>
												</h:inputText>
											</td>
										</tr>
										</tbody>
									</table>
								</fieldset>
							</td>
							<td>
								<fieldset id="group1fields" title="Group1 Fields">
									<table>
										<tbody>
										<tr>
											<td><h:outputLabel value="#{lbl.phone} (VG1)" /></td>
											<td>:</td>
											<td>
												<h:inputText id="txt_phone" value="#{validatorPageBean.phone}">
													<s:commonsValidator type="maxlength" arg="#{lbl.phone}"  client="false" server="true" maxlength="15">
														<s:validatorVar name="groupId" value="group1" />
													</s:commonsValidator>
													<s:commonsValidator type="minlength" arg="#{lbl.phone}"  client="false" server="true" minlength="7">
														<s:validatorVar name="groupId" value="group1" />
													</s:commonsValidator>
												</h:inputText>
											</td>
										</tr>
										<tr>
											<td><h:outputLabel value="#{lbl.address} (VG1)" /></td>
											<td>:</td>
											<td>
												<h:inputTextarea id="txt_address" value="#{validatorPageBean.address}">
													<s:commonsValidator type="maxlength" arg="#{lbl.address}"  client="false" server="true" maxlength="30">
														<s:validatorVar name="groupId" value="group1" />
													</s:commonsValidator>
												</h:inputTextarea>
											</td>
										</tr>
										</tbody>
									</table>
								</fieldset>
							</td>
							<td>
								<fieldset id="group2fields" title="Group2 Fields">
									<table>
										<tbody>
										<tr>
											<td><h:outputLabel value="#{lbl.jobid} (VG2)" /></td>
											<td>:</td>
											<td>
												<h:inputText id="txt_jobid" value="#{validatorPageBean.jobid}">
													<s:commonsValidator type="intRange" arg="#{lbl.jobid}"  client="false" server="true" min="1" max="999">
														<s:validatorVar name="groupId" value="group2" />
													</s:commonsValidator>
												</h:inputText>
											</td>
										</tr>
										<tr>
											<td><h:outputLabel value="#{lbl.jobtitle} (VG2)" /></td>
											<td>:</td>
											<td>
												<h:inputText id="txt_jobtitle" value="#{validatorPageBean.jobtitle}">
													<s:commonsValidator type="maxlength" arg="#{lbl.jobtitle}"  client="false" server="true" maxlength="15">
														<s:validatorVar name="groupId" value="group2" />
													</s:commonsValidator>
												</h:inputText>
											</td>
										</tr>
										</tbody>
									</table>
								</fieldset>
							</td>
						</tr>
						</tbody>
					</table>
					<td>
				</tr>
				<tr>
					<td colspan="2">
						<h:commandButton type="submit" value="Validate Fields with No-Group" action="None">
						</h:commandButton>
						<h:commandButton type="submit" value="Validate Group1 Fields Only" action="None"
							onclick="setActiveValidationGroup('group1');">
						</h:commandButton>
						<h:commandButton type="submit" value="Validate Group2 Fields Only" action="None"
							onclick="setActiveValidationGroup('group2');">
						</h:commandButton>
					</td>
				</tr>
				<tr><td>&nbsp;</td></tr>
				<tr>
					<td title="INFO">
					<fieldset id="i1">
					NV  : Field has no validator<BR>
					NG  : Field has validator but no group assigned<BR>
					VG1 : Field has group1 validators<BR>
					VG2 : Field has group2 validators
					</fieldset>
					</td>
					<td>
					<fieldset id="i2">
					Company Name : has no validator<BR>
					Name : String with minlength=3, maxlength=20<BR>
					Age  : Integer between 20 and 60<BR>
					Phone : String with minlength=7, maxlength=15<BR>
					Address : String with maxlength=15<BR>
					Job ID  : Integer between 1 and 999<BR>
					Job Title : String with maxlength=15
					</fieldset>
					</td>
				</tr>
				</tbody>
			</table>

			<input type="hidden" id="fld_activeValidationGroup" name="fld_activeValidationGroup" value="novgroup" />
			<s:validatorScript functionName="validateForm"/>
		</h:form>
		
	</body>
	</f:view>
</html>  
